using System;
using System.Collections.Generic;
using System.Text;

namespace PSE.Deployment.SetupBase.Commands
{
    public class CommandFactory
    {
        // Available commands
        private const string InstallCommand = "/install";
        private const string UninstallCommand = "/uninstall";
        private const string ChangeCommand = "/change";
        private const string RepairCommand = "/repair";
        private const string HotFixCommand = "/hotfix";
        private const string ServicePackCommand = "/servicepack";
        private const string HelpCommand = "/help";

        // Short name for the available commands.
        private const string InstallShortCommand = "/i";
        private const string UninstallShortCommand = "/u";
        private const string ChangeShortCommand = "/c";
        private const string RepairShortCommand = "/r";
        private const string HotFixShortCommand = "/hf";
        private const string ServicePackShortCommand = "/sp";
        private const string HelpShortCommand = "/?";

        private static Dictionary<string, ICommand> _instances = new Dictionary<string,ICommand>();

        public static ICommand Instance(string commandName)
        {
            if (_instances.ContainsKey(commandName))
            {
                return _instances[commandName];
            }

            ICommand command = null;

            switch (commandName)
            {
                case InstallCommand:
                case InstallShortCommand:
                    command = new InstallCommand();
                    _instances.Add(commandName, command);
                    return command;

                case UninstallCommand:
                case UninstallShortCommand:
                    command = new UninstallCommand();
                    _instances.Add(commandName, command);
                    return command;

                case ChangeCommand:
                case ChangeShortCommand:
                    command = new ChangeCommand();
                    _instances.Add(commandName, command);
                    return command;

                case RepairCommand:
                case RepairShortCommand:
                    command = new RepairCommand();
                    _instances.Add(commandName, command);
                    return command;

                case HotFixCommand:
                case HotFixShortCommand:
                    command = new HotFixCommand();
                    _instances.Add(commandName, command);
                    return command;

                case ServicePackCommand:
                case ServicePackShortCommand:
                    command = new ServicePackCommand();
                    _instances.Add(commandName, command);
                    return command;

                case HelpCommand:
                case HelpShortCommand:
                    command = new HelpCommand();
                    _instances.Add(commandName, command);
                    return command;
                    
                default:
                    Messages.CommandSyntaxError(commandName);
                    return null;
            }
        }
    }
}
